<?php
namespace App\WxPay;


/**
 * 转账接口类
 */
class Transfers_pub extends Wxpay_client_pub
{
    function __construct()
    {
        //设置接口链接
        $this->url = "https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers";
        //设置curl超时时间
        $this->curl_timeout = WxPayConf_pub::CURL_TIMEOUT;
    }

    /**
     * 生成接口参数xml
     */
    function createXml()
    {
        try
        {
            //检测必填参数
            if($this->parameters["partner_trade_no"] == null)
            {
                throw new SDKRuntimeException("缺少统一支付接口必填参数partner_trade_no！"."<br>");
            }elseif($this->parameters["desc"] == null){
                throw new SDKRuntimeException("缺少统一支付接口必填参数desc！"."<br>");
            }elseif ($this->parameters["amount"] == null ) {
                throw new SDKRuntimeException("缺少统一支付接口必填参数amount！"."<br>");
            }elseif ($this->parameters["openid"] == null) {
                throw new SDKRuntimeException("缺少统一支付接口必填参数openid！"."<br>");
            }elseif ($this->parameters["check_name"] != "NO_CHECK" &&
                $this->parameters["re_user_name"] == NULL){
                throw new SDKRuntimeException("统一支付接口中，缺少必填参数re_user_name！check_name不为NO_CHECK时，re_user_name为必填参数！"."<br>");
            }
            $this->parameters["mch_appid"] = WxPayConf_pub::APPID;//公众账号ID
            $this->parameters["mchid"] = WxPayConf_pub::MCHID;//商户号
            $this->parameters["spbill_create_ip"] = $_SERVER['REMOTE_ADDR'];//终端ip
            $this->parameters["nonce_str"] = $this->createNoncestr();//随机字符串
            $this->parameters["sign"] = $this->getSign($this->parameters);//签名
            return  $this->arrayToXml($this->parameters);
        }catch (SDKRuntimeException $e)
        {
            die($e->errorMessage());
        }
    }

    /**
     * 	作用：获取结果，使用证书通信
     */
    function getResult()
    {
        $this->postXmlSSL();
        $this->result = $this->xmlToArray($this->response);
        return $this->result;
    }

}